package com.example.myspringboot.business.schedule;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduleTest {

    @Scheduled(cron = "* * * * * ?")
    public void run1() {
        System.out.println(Thread.currentThread().getName() + "------run1···" + new Date());
    }

    @Scheduled(cron = "0/5 * * * * ?")
    public void run2() {
        System.out.println(Thread.currentThread().getName() + "------run2···" + new Date());
        try {
            Thread.sleep(4000);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /** 下面的定时任务通过configurer管理，所以没有注解 **/

    public void run3() {
        System.out.println(Thread.currentThread().getName() + "------run3···" + new Date());
    }

    public void run4() {
        System.out.println(Thread.currentThread().getName() + "------run4···" + new Date());
        try {
            Thread.sleep(4000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
